﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DataBase
{
    public partial class ServerAdd : Form
    {
        int ID = 0;
        public ServerAdd(int id)
        {
            ID = id;
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            if (ID > 0)
            {
                ServerInfo obj = AccessDAL.FindOneByID(ID);
                this.textBox1.Text = obj.IP;
                this.textBox2.Text = obj.UserName;
                this.textBox3.Text = obj.UserPwd;
                this.textBox4.Text = obj.Alias;
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (ID == 0)
            {
                if (AccessDAL.Save(this.textBox4.Text, this.textBox1.Text, this.textBox2.Text, this.textBox3.Text))
                {
                    MessageBox.Show("保存成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
            else
            {
                if (AccessDAL.Update(ID, this.textBox4.Text, this.textBox1.Text, this.textBox2.Text, this.textBox3.Text))
                {
                    MessageBox.Show("保存成功");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("保存失败");
                }
            }
        }
    }
}
